package com.example.esdemo.entity;

import lombok.Data;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;

import java.util.List;

/**
 * @author kaibo
 * @date 2019/10/21 15:01
 * @GitHub：https://github.com/yuxuelian
 * @email：kaibo1hao@gmail.com
 * @description：
 */

@Data
public class PageEntity<T> {

    public static <T> PageEntity<T> map(AggregatedPage<T> orig) {
        PageEntity<T> dest = new PageEntity<>();
        dest.setTotal(orig.getTotalElements());
        dest.setPages(orig.getTotalPages());
        dest.setCurrent(orig.getNumber());
        dest.setSize(orig.getSize());
        dest.setRecords(orig.getContent());
        return dest;
    }

    private long total;
    private long pages;
    private long current;
    private long size;
    private List<T> records;

}
